const path = require('path');
// const HtmlwebpackPlugin = require('html-webpack-plugin');
const TransferWebpackPlugin = require('transfer-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');

// 定义了一些文件夹的路径
const ROOT_PATH = path.resolve(__dirname);
const APP_PATH = path.resolve(ROOT_PATH, 'app');
const BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
const entry = require('./entry.js');

module.exports = {
    mode: 'none', // 设置生产环境
    entry: entry('pro'),
    output: {
        path: BUILD_PATH,
        filename: './Scripts/[name].js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: { presets: ['env', "stage-0"] }
                    }
                ]
            },{
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    // fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css-loader',
                            options: { minimize: true }
                        },{
                            loader: 'postcss-loader',
                            options: {
                                config: {
                                    path: './postcss.config.js'
                                }
                            }
                        },
                        'sass-loader'
                    ]
                })
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin('dist'),
        // 把指定文件夹下的文件复制到指定的目录
        new TransferWebpackPlugin([
            {from: './public/vendor', to: './vendor'},
            {from: './public/images', to: './images'},
        ],path.resolve(__dirname)),
        new ExtractTextPlugin({filename: 'Content/[name].css', disable: false, allChunks: true}),
        // 混淆压缩js和css // 已经舍弃
        /*new webpack.optimize.UglifyJsPlugin({
            compress: { warnings: false },
            except: ['$', 'exports', 'require'] // 排除关键字
        })*/
        
        new UglifyJsPlugin({
            uglifyOptions: {
                ie8: false, // Enable IE8 Support
                safari10: true, // Enable work around Safari 10/11 bugs in loop scoping and await
                toplevel: true, // Enable top level variable and function name mangling and to drop unused variables and functions
                compress: true,
                except: ['$', 'exports', 'require', 'default']
            }
        })
        
    ]
}